package com.noname.lib_base_java.util;

import android.content.Context;
import android.content.res.Resources;
import android.os.Build;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;

/**
 * Author: Lmoumou
 * Date: 2018-12-19 14:16
 * 文件名: StatusBarUtil
 * 描述:
 */
public class StatusBarUtil {


    public static void setHeight(Context context, View view) {
        if (Build.VERSION.SDK_INT >= 19) {
            ViewGroup.LayoutParams lp = view.getLayoutParams();
            if (lp instanceof ViewGroup.MarginLayoutParams) {
                lp.height = getStatusBarHeight(context);
            }
            view.setLayoutParams(lp);
        }
    }


    public static int getStatusBarHeight(Context context) {
        int result = 24;

        int resId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (resId > 0) {
            result = context.getResources().getDimensionPixelSize(resId);
        } else {
            result = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
                    result, Resources.getSystem().getDisplayMetrics());
        }
        return result;

    }

}
